<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/hexo-blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/hexo-blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/hexo-blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/hexo-blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/hexo-blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/hexo-blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/hexo-blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="Chapter[0].name=”前言\0”报告面向有一定编程基础的人，旨在让大家更加理解指针，能用、去用、敢用的境界。   Chapter-&amp;gt;*(node).name=”为什么要写本报告\0”我在学习指针的时候遇到了很多困难，导致我很难去理解它，但是在之后的数据结构学习过程中需要用到指针，我只好重新翻开课本去看指针，对指针有了更好更简单的理解，希望把这种理解的方式告诉给大家。在生活中我在">
<meta property="og:type" content="article">
<meta property="og:title" content="指针：兰花指到弹指神通">
<meta property="og:url" content="https://son9wx.gitee.io/hexo-blog/overcome-pointer/index.html">
<meta property="og:site_name" content="son9wxのblog">
<meta property="og:description" content="Chapter[0].name=”前言\0”报告面向有一定编程基础的人，旨在让大家更加理解指针，能用、去用、敢用的境界。   Chapter-&amp;gt;*(node).name=”为什么要写本报告\0”我在学习指针的时候遇到了很多困难，导致我很难去理解它，但是在之后的数据结构学习过程中需要用到指针，我只好重新翻开课本去看指针，对指针有了更好更简单的理解，希望把这种理解的方式告诉给大家。在生活中我在">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/x12*T276cospEYp5eRsKHzrNuDCLqMGFrdyw6O.gvn0!/r/dDYBAAAAAAAA">
<meta property="og:updated_time" content="2018-11-11T13:45:55.095Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="指针：兰花指到弹指神通">
<meta name="twitter:description" content="Chapter[0].name=”前言\0”报告面向有一定编程基础的人，旨在让大家更加理解指针，能用、去用、敢用的境界。   Chapter-&amp;gt;*(node).name=”为什么要写本报告\0”我在学习指针的时候遇到了很多困难，导致我很难去理解它，但是在之后的数据结构学习过程中需要用到指针，我只好重新翻开课本去看指针，对指针有了更好更简单的理解，希望把这种理解的方式告诉给大家。在生活中我在">
<meta name="twitter:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/x12*T276cospEYp5eRsKHzrNuDCLqMGFrdyw6O.gvn0!/r/dDYBAAAAAAAA">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/hexo-blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://son9wx.gitee.io/hexo-blog/overcome-pointer/">





  <title>指针：兰花指到弹指神通 | son9wxのblog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/hexo-blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">son9wxのblog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/hexo-blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/hexo-blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/hexo-blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/hexo-blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://son9wx.gitee.io/hexo-blog/hexo-blog/overcome-pointer/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="son9wx">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/hexo-blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="son9wxのblog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">指针：兰花指到弹指神通</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-11T17:13:33+08:00">
                2018-11-11
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/x12*T276cospEYp5eRsKHzrNuDCLqMGFrdyw6O.gvn0!/r/dDYBAAAAAAAA" alt="指针"></p>
<h1 id="Chapter-0-name-”前言-0”"><a href="#Chapter-0-name-”前言-0”" class="headerlink" title="Chapter[0].name=”前言\0”"></a>Chapter[0].name=”前言\0”</h1><p>报告面向有一定编程基础的人，旨在让大家更加理解指针，能用、去用、敢用的境界。  </p>
<h2 id="Chapter-gt-node-name-”为什么要写本报告-0”"><a href="#Chapter-gt-node-name-”为什么要写本报告-0”" class="headerlink" title="Chapter-&gt;*(node).name=”为什么要写本报告\0”"></a>Chapter-&gt;*(node).name=”为什么要写本报告\0”</h2><p>我在学习指针的时候遇到了很多困难，导致我很难去理解它，但是在之后的数据结构学习过程中需要用到指针，我只好重新翻开课本去看指针，对指针有了更好更简单的理解，希望把这种理解的方式告诉给大家。在生活中我在许多场合{润学讲坛，班级分享，Python是大数据实验室的公开课等}已经分享了我对指针的理解，听过的童鞋表示这种方式可以使他们更加理解指针的内涵。在实验室讲完课后需要出一份文档来记录，我就写下了这篇文档。<br><a id="more"></a></p>
<h2 id="Chapter-gt-node-1-name-”源于对未知事物的恐惧-0”"><a href="#Chapter-gt-node-1-name-”源于对未知事物的恐惧-0”" class="headerlink" title="Chapter-&gt;*(node+1).name=”源于对未知事物的恐惧\0”"></a>Chapter-&gt;*(node+1).name=”源于对未知事物的恐惧\0”</h2><p>我们想象这样一个场景，在你面前有很多盒子，他们被布包裹起来，你看不清里面的内容，盒子上面有一个小洞，你需要将手伸入小洞去触摸盒子里面的物体，我们摸到一撮毛的时候，你会害怕，也许打开包裹盒子的布后，他只是一个简单的毛绒玩具，恐惧源于未知，有一种恐惧是你不知道将会发生什么，另一种恐惧是你不知道他是怎么发生的，而第一种恐惧呢都是源于自己内心的焦虑，比如将一个小孩单独关在一个黑暗的房间中，第二种恐惧，是一种现象，超过了自身的知识范围，比如说小孩看到水在翻滚，也会感到恐惧，因为他解释不了，水为什么会运动的这么剧烈？在计算机中，我们相计算机申请空间通常是计算机，通过某种算法分配给我们的一块大小合适的空间，正是因为随机性，我们不知道这块空间在计算机内存中的哪一个位置，正是源于这种恐惧，我们才会引入地址的概念，那指针的作为储存地址的一个载体，应运而生。  </p>
<h2 id="Chapter-gt-node-2-name-”排版说明-0”"><a href="#Chapter-gt-node-2-name-”排版说明-0”" class="headerlink" title="Chapter-&gt;*(node+2).name=”排版说明\0”"></a>Chapter-&gt;*(node+2).name=”排版说明\0”</h2><p>语法描述如下  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> *<span class="title">find_num</span><span class="params">(<span class="keyword">int</span> *arr, <span class="keyword">int</span> find, <span class="keyword">int</span>(my_compare)(<span class="keyword">int</span> a, <span class="keyword">int</span> b))</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">int</span> *arrptr = arr;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">-1</span>; i &lt; <span class="number">10</span>; ++i, arrptr++)</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="keyword">if</span> (my_compare(*arrptr, find))</span><br><span class="line">      <span class="keyword">return</span> arrptr;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">NULL</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>p.我想要突出重点的代码块会用<strong>加粗</strong>的方式标出，另外可选学习内容会用 <strong><em>斜粗体</em></strong> 标出。<br>章节特点如下<br>章节{Chapter}是我定义的一个结构体，她有一个属性就是<code>char * name</code>代表章节的名字。另外每小节名字也已数组的形式存储在node数组中，node如同章节一样，他也包括了一个char * name。  </p>
<h2 id="Chapter-gt-node-3-name-”致谢-0”"><a href="#Chapter-gt-node-3-name-”致谢-0”" class="headerlink" title="Chapter-&gt;*(node+3).name=”致谢\0”"></a>Chapter-&gt;*(node+3).name=”致谢\0”</h2><p>我无法列举出对这个报告编写是做出贡献的所有人。<br>我要感谢来听我讲课的同学们，他们帮助我发现录入错误，提出了改进意见，并在教学过程忍受着草稿形式的教材。他们对我的作品反应向我提供了有益的帮助。<br>我还要感谢我们班级的管理人员，校科协的管理人员，Python大数据实验室的管理人员，他们提供给我了一次次展示自己的机会，提出了许多有价值的建议。<br>现在是开始学习的时候了，我预祝大家在学习指针的过程中找到快乐。<br><a href="mailto:son9wx@QQ.com" target="_blank" rel="noopener">son9wx@QQ.com</a>
 </p>
<h1 id="Chapter-1-name-”愤怒的送餐员-0”"><a href="#Chapter-1-name-”愤怒的送餐员-0”" class="headerlink" title="Chapter[1].name=”愤怒的送餐员\0”"></a>Chapter[1].name=”愤怒的送餐员\0”</h1><p>实验室的一个朋友李刚刚码了一上午代码，有些饿了，于是在网上定了一个外卖，送餐员给他打电话问送到哪时。“送到一个黑衣服黑裤子的人手里。”李刚刚说。送餐员气愤的挂掉了电话。  </p>
<h2 id="Chapter-1-gt-node-name-”李刚刚的故事-0”"><a href="#Chapter-1-gt-node-name-”李刚刚的故事-0”" class="headerlink" title="Chapter+1-&gt;*(node).name=”李刚刚的故事\0”"></a>Chapter+1-&gt;*(node).name=”李刚刚的故事\0”</h2><p>在现实生活中，上面的故事显然是不符合常理的。现在，我们抛弃现实生活中的实际。我们世界上假设只有两个人。  </p>
<p>这两个人的衣装是不同的，我们显然可以根据这种特征去定位一个人。但是人数增多到一个量级后我们就不能根据人的衣装甚至名字来找到他。   </p>
<h2 id="Chapter-1-gt-node-1-name-”送餐员的需要-0”"><a href="#Chapter-1-gt-node-1-name-”送餐员的需要-0”" class="headerlink" title="Chapter+1-&gt;*(node+1).name=”送餐员的需要\0”"></a>Chapter+1-&gt;*(node+1).name=”送餐员的需要\0”</h2><p>我不禁在想，送餐员需要一种可以定位到人的信息，这种信息是什么呢？我们能否根据这种信息具有的特性来反馈给送餐员呢？<br>我总结了一下这类信息，发现他们具有以下两个性质：  </p>
<ul>
<li>确定性</li>
<li>唯一性  </li>
</ul>
<h2 id="Chapter-1-gt-node-2-name-”确定唯一的信息-0”"><a href="#Chapter-1-gt-node-2-name-”确定唯一的信息-0”" class="headerlink" title="Chapter+1-&gt;*(node+2).name=”确定唯一的信息\0”"></a>Chapter+1-&gt;*(node+2).name=”确定唯一的信息\0”</h2><p>这种信息到底是什么？我们在日常生活中来确定一个人只需要一个具体的位置和一个可以联系到你的电话号码。当然，我们身上所有的信息也可以来确定一个人（每个人都是独一无二的）。那我们为什么不把自己所有的信息告诉送餐员呢？显然他太大了！可能你自己都不知道你自己的所有信息。</p>
<h1 id="Chapter-2-name-”程序中的地址-0”"><a href="#Chapter-2-name-”程序中的地址-0”" class="headerlink" title="Chapter[2].name=”程序中的地址\0”"></a>Chapter[2].name=”程序中的地址\0”</h1><p>想一想在编写计算机程序中为了找到一个地址，你会怎么做。  </p>
<h2 id="Chapter-2-gt-node-name-”取地址-amp-0”"><a href="#Chapter-2-gt-node-name-”取地址-amp-0”" class="headerlink" title="Chapter+2-&gt;*(node).name=”取地址\&amp;\0”"></a>Chapter+2-&gt;*(node).name=”取地址\&amp;\0”</h2><p>当然在计算机中我们为了修改一个数组中的数据将数组的全部元素作为一个参数去传入函数中是不可以接受的（他太缓慢了），那为什么之前我们写程序中传入了数组也没有感觉程序运行的缓慢。有两个原因：</p>
<ul>
<li>数组长度太小（100以内？）</li>
<li>在c语言中，数组名就是地址（没想到吧？）  </li>
</ul>
<p>于是我们需要传入数组的地址，还好在许多高级语言中把“&amp;”规定为取地址符，使用它他可以获取到任意一个变量在计算机中的位置。  </p>
<h2 id="Chapter-2-gt-node-1-name-”间接访问-0”"><a href="#Chapter-2-gt-node-1-name-”间接访问-0”" class="headerlink" title="Chapter+2-&gt;(node+1).name=”间接访问\\0”"></a>Chapter+2-&gt;<em>(node+1).name=”间接访问\</em>\0”</h2><p>我们拿到一个地址后，这是一个整数型的数字，他是某一块内存的编号，通过“*”可以针对这个编号去访问计算机内存上的内容。也就是说我们想传递一个超大数组的时候，并不需要将这个超大元素传过去，只需要把这个超大数组的首地址地址传入，在函数内需要访问时，我们再去访问他即可。  </p>
<h1 id="Chapter-3-name-”指针模型-0”"><a href="#Chapter-3-name-”指针模型-0”" class="headerlink" title="Chapter[3].name=”指针模型\0”"></a>Chapter[3].name=”指针模型\0”</h1><p>以编程者的方式看待程序中的变量  </p>
<h2 id="Chapter-3-gt-node-name-”思维转变-0”"><a href="#Chapter-3-gt-node-name-”思维转变-0”" class="headerlink" title="Chapter+3-&gt;*(node).name=”思维转变\0”"></a>Chapter+3-&gt;*(node).name=”思维转变\0”</h2><p>以前在学习这部分知识的时候，教科书上引导我们使用计算机的方式去理解指针，我们才会越来越糊涂，现在我们需要转变一下思维，以编程者的方式去重新看待指针。</p>
<h2 id="Chapter-3-gt-node-1-name-”简单模型-0”"><a href="#Chapter-3-gt-node-1-name-”简单模型-0”" class="headerlink" title="Chapter+3-&gt;*(node+1).name=”简单模型\0”"></a>Chapter+3-&gt;*(node+1).name=”简单模型\0”</h2><p>当我们尝试声明一个变量，现在这个变量在我们的视角里是这样的。</p>
<p>实线表示我们知道的内容，虚线代表实际上存在，但是我们不知道的内容，因为这个内存位置是计算机在内存中寻找到一块合适的位置，申请出来的。也就是当我们在程序中int a=5的时候，我们现在只知道a的值是5，对于其他内容我们是一无所知的。但是当我们想要去找到a的地址，我们想要去知道a的上下内存空间存储了什么内容的时候，我们需要使用在第三章我们提到的取地址符进行访问</p>
<h2 id="Chapter-3-gt-node-2-name-”一级指针模型-0”"><a href="#Chapter-3-gt-node-2-name-”一级指针模型-0”" class="headerlink" title="Chapter+3-&gt;*(node+2).name=”一级指针模型\0”"></a>Chapter+3-&gt;*(node+2).name=”一级指针模型\0”</h2><p>人为的去开辟一个空间来存储这个地址，那我们说这个空间就是指针，或者说一级指针模型，那在程序中表示我在前面给回给出来，为了方便区分部分我把颜色分开了。如果●代表a这个变量，那么他的外部红色的线条框代表&amp;a。指针模型与他类似，我们用*a代表●，而外部红色是a。@他就像把之前模型反过来表示的一样。</p>
<h2 id="Chapter-3-gt-node-3-name-”二级多级指针模型-0”"><a href="#Chapter-3-gt-node-3-name-”二级多级指针模型-0”" class="headerlink" title="Chapter+3-&gt;*(node+3).name=”二级多级指针模型\0”"></a>Chapter+3-&gt;*(node+3).name=”二级多级指针模型\0”</h2><p>仿照上述变换，加一层指针的话，应该变成如下图所示：</p>
<p>此后无论多少级的指针均可以用这个模型来表示了。我常常把他比作大娃娃里面的小娃娃那个玩具一样一层一层的，我把指针模型的界面给大家展示出来了，其实我们把图像变成立体图应该也可以想得通。</p>
<h1 id="Chapter-4-name-”换不过来的交换-0”"><a href="#Chapter-4-name-”换不过来的交换-0”" class="headerlink" title="Chapter[4].name=”换不过来的交换\0”"></a>Chapter[4].name=”换不过来的交换\0”</h1><p>这块我们会使用指针进行一些程序开发，我们像大多数人一样以swap（交换函数）为例子，开始我们的实战。</p>
<h2 id="Chapter-4-gt-node-name-”最简单的交换-0”"><a href="#Chapter-4-gt-node-name-”最简单的交换-0”" class="headerlink" title="Chapter+4-&gt;*(node).name=”最简单的交换\0”"></a>Chapter+4-&gt;*(node).name=”最简单的交换\0”</h2><p>下面是一个最简单的交换例子1，因为不涉及到参数，我们只需要显示的去改变a和b的值即可。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">swap_demo</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> a = <span class="number">1</span>, b = <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">int</span> *aptr = &amp;a, *bptr = &amp;b;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"value of a is %d,adress of a is %p\n"</span>, a, aptr);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"value of b is %d,adress of b is %p\n"</span>, b, bptr);</span><br><span class="line">    *aptr = <span class="number">2</span>;</span><br><span class="line">    *bptr = <span class="number">1</span>; </span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"value of a is %d,adress of a is %p\n"</span>, a, aptr);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"value of b is %d,adress of b is %p\n"</span>, b, bptr);</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这只是个热身，我们先不要着急继续，我们先思考一下，我们到底在让什么进行交换，是值，地址还是指针的地址，很多同学因为这个不清楚而导致无法写出来程序。<br>对了，我们只是在交换两个变量的值，所以不按照我的写法你自己是不是也可以写出来一个简单的例子呢？</p>
<h2 id="Chapter-4-gt-node-1-name-”函数的交换-0”"><a href="#Chapter-4-gt-node-1-name-”函数的交换-0”" class="headerlink" title="Chapter+4-&gt;*(node+1).name=”函数的交换\0”"></a>Chapter+4-&gt;*(node+1).name=”函数的交换\0”</h2><p>试想一下这种情况，你要把两个变量在函数里进行交换，但是函数中传入的参数并不会让你完成这种交换，因为作为参数在函数结束时是不会发生改变的，c语言中为了解决这个问题提供的地址传入的方式，设想一下，我们传入了两个数的地址，而在函数体内是对他们地址所指向的值进行交换，这样既不会改变参数中的值又可以完成地址的交换了。<br>下面我给出函数：<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">swap_function</span><span class="params">(<span class="keyword">int</span> *p1, <span class="keyword">int</span> *p2)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">int</span> c = *p1;</span><br><span class="line">  *p1 = *p2;</span><br><span class="line">  *p2 = c;</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="Chapter-4-gt-node-2-name-”地址的交换-0”"><a href="#Chapter-4-gt-node-2-name-”地址的交换-0”" class="headerlink" title="Chapter+4-&gt;*(node+2).name=”地址的交换\0”"></a>Chapter+4-&gt;*(node+2).name=”地址的交换\0”</h2><p>那我们既然通过传入地址参数改变了值，当我们想改变地址的时候应该传入什么呢？因为函数执行结束不会改变参数的值，那我们只好传入地址的地址，这样可能会有点难以理解，我们我们可以应用我刚刚提出来的模型去想下，我们传入的地址只是为了改变我们要改变的地址，取道我们要改变的地址来改变。这样可能一时难以理解，多画图相信你可以熟练掌握。我这里给出地址交换的源码。看看你和我想的是否一样。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">swap_adress_function</span><span class="params">(<span class="keyword">int</span> **a, <span class="keyword">int</span> **b)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">int</span> *c = *a;</span><br><span class="line">  *a = *b;</span><br><span class="line">  *b = c;</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="Chapter-5-name-”字符指针-0”"><a href="#Chapter-5-name-”字符指针-0”" class="headerlink" title="Chapter[5].name=”字符指针\0”"></a>Chapter[5].name=”字符指针\0”</h1><p>搞懂了这两个交换，我们再来重新认识一下c语言的字符指针char*吧！</p>
<h2 id="Chapter-5-gt-node-name-”详解-0”"><a href="#Chapter-5-gt-node-name-”详解-0”" class="headerlink" title="Chapter+5&gt;*(node).name=”详解\0”"></a>Chapter+5&gt;*(node).name=”详解\0”</h2><p>我们经常用到char* a=“ABC\0”那么这句好话到底是什么意思呢？以这个为例子<br>我们要输出ABC怎么实现。我们想取道B字母怎么实现。利用指针模型，我们知道a是一个指针变量，他存储着A字符的地址，他的下一个地址存放的是B，同理他的下下个地址单元存放的是C。c语言怎么去实现分配单元空间呢？‘\0‘表示一个字符串的结束，无论你申请多大的空间，只要字符串中出现了‘\0‘这个指针就停止了，这也就是为什么你申请一个100长度的数组，调用strlen函数时他总是可以传给你这个字符串的长度而不是100。同时，我们想要在键盘上输入一个字符串没有办法输入‘\0‘怎么办？在c语言中，我们要输入字符串用’%s’来作为格式化输入，程序会为我们自动补充‘\0‘。</p>
<h2 id="Chapter-5-gt-node-1-name-”寻找大兵雷恩-0”"><a href="#Chapter-5-gt-node-1-name-”寻找大兵雷恩-0”" class="headerlink" title="Chapter+5-&gt;*(node+1).name=”寻找大兵雷恩\0”"></a>Chapter+5-&gt;*(node+1).name=”寻找大兵雷恩\0”</h2><p>我们想要实现在一个支付床str里面找到char find这个字符该怎么办呢？你可以先思考一下，我给出我的解决方案。<br>他非常简单，仅仅使用res来保存现在字符串的未知，当遍历完字符串依然没有我们需要的字符时，我们将-1返回即可。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">find_char</span><span class="params">(<span class="keyword">char</span> *str, <span class="keyword">char</span> find)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">int</span> res = <span class="number">-1</span>;<span class="comment">//计数器</span></span><br><span class="line">  <span class="keyword">while</span> (str++)</span><br><span class="line">  &#123;</span><br><span class="line">++res;</span><br><span class="line">    <span class="keyword">if</span> ((*str) == find)<span class="comment">//如果找到</span></span><br><span class="line">    &#123;</span><br><span class="line">      <span class="keyword">return</span> res;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ((*str) == <span class="string">'\0'</span>)<span class="comment">//退出条件</span></span><br><span class="line">    &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="number">-404</span>;<span class="comment">//其他情况</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="Chapter-6-name-”其他案例-0”"><a href="#Chapter-6-name-”其他案例-0”" class="headerlink" title="Chapter[6].name=”其他案例\0”"></a>Chapter[6].name=”其他案例\0”</h1><p>到这里，你的指针知识已经很强大了，我下面提供了几个练习案例，你可以先尝试自己编写，在于我的程序对应看一看你的进步吧！</p>
<ul>
<li><p>前序创建和遍历二叉树</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TREESTR <span class="meta-string">"abd--e--cf--g--\0"</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">node</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">  <span class="class"><span class="keyword">struct</span> <span class="title">node</span> *<span class="title">left</span>;</span></span><br><span class="line">  <span class="class"><span class="keyword">struct</span> <span class="title">node</span> *<span class="title">right</span>;</span></span><br><span class="line">  <span class="keyword">char</span> data;</span><br><span class="line">&#125; node, *nodeptr;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">bitree</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">  <span class="comment">// int num;</span></span><br><span class="line">  nodeptr root;</span><br><span class="line">&#125; bitree, *bitreeptr;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc 为bt树bt树封装了一棵树的root节点</span></span><br><span class="line"><span class="comment"> * - malloc创建bt</span></span><br><span class="line"><span class="comment"> * @param (bitree **) bt 树根</span></span><br><span class="line"><span class="comment"> * @return void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">creat_bitree_head</span><span class="params">(bitreeptr btp)</span></span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc 为bt树创建node节点</span></span><br><span class="line"><span class="comment"> * - 为bt树创建node节点</span></span><br><span class="line"><span class="comment"> * @param (bitree) bt 树根</span></span><br><span class="line"><span class="comment"> * @param (node *) np 树根或者子树根或者叶子节点</span></span><br><span class="line"><span class="comment"> * @return void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">creat_bitree_node</span><span class="params">(bitree bt, nodeptr *np, <span class="keyword">char</span> **elem)</span></span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc 通过根节点遍历二叉树！</span></span><br><span class="line"><span class="comment"> * - 通过根节点遍历二叉树！</span></span><br><span class="line"><span class="comment"> * @param (node) root 某棵树的根节点</span></span><br><span class="line"><span class="comment"> * @return void [打印前序遍历的二叉树，原则上与构造字符串相同]</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print_bitree</span><span class="params">(node root)</span></span>;</span><br><span class="line"><span class="comment">// 模拟main环境</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">bitree_main</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">bitree_main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  bitree bt;</span><br><span class="line">  <span class="keyword">char</span> *str = TREESTR;</span><br><span class="line">  creat_bitree_head(&amp;bt);</span><br><span class="line">  creat_bitree_node(bt, &amp;((&amp;bt)-&gt;root), &amp;str);</span><br><span class="line">  print_bitree(*((&amp;bt)-&gt;root));</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">creat_bitree_head</span><span class="params">(bitreeptr btp)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="comment">// (*btp) = (bitreeptr)malloc(sizeof(bitree));</span></span><br><span class="line">  <span class="comment">// if (!*btp)</span></span><br><span class="line">  <span class="comment">//   exit(-500);</span></span><br><span class="line">  <span class="comment">// btp-&gt;num = 1;</span></span><br><span class="line">  btp-&gt;root = (nodeptr)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(node));</span><br><span class="line">  <span class="keyword">if</span> (!btp-&gt;root)</span><br><span class="line">    <span class="built_in">exit</span>(<span class="number">-500</span>);</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">creat_bitree_node</span><span class="params">(bitree bt, nodeptr *np, <span class="keyword">char</span> **elem)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">char</span> cur = *((*elem)++);</span><br><span class="line">  <span class="keyword">if</span> (cur == <span class="string">'-'</span>)</span><br><span class="line">  &#123;</span><br><span class="line">    (*np) = <span class="literal">NULL</span>;</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  (*np)-&gt;data = cur;</span><br><span class="line">  (*np)-&gt;left = (nodeptr)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(node));</span><br><span class="line">  <span class="keyword">if</span> (!(*np)-&gt;left)</span><br><span class="line">    <span class="built_in">exit</span>(<span class="number">-500</span>);</span><br><span class="line"></span><br><span class="line">  (*np)-&gt;right = (nodeptr)<span class="built_in">malloc</span>(<span class="keyword">sizeof</span>(node));</span><br><span class="line">  <span class="keyword">if</span> (!(*np)-&gt;right)</span><br><span class="line">    <span class="built_in">exit</span>(<span class="number">-500</span>);</span><br><span class="line"></span><br><span class="line">  creat_bitree_node(bt, &amp;((*np)-&gt;left), elem);</span><br><span class="line">  creat_bitree_node(bt, &amp;((*np)-&gt;right), elem);</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print_bitree</span><span class="params">(node n)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="built_in">printf</span>(<span class="string">"%c"</span>, n.data);</span><br><span class="line">  <span class="keyword">if</span> (n.left)</span><br><span class="line">    print_bitree(*(n.left));</span><br><span class="line">  <span class="keyword">else</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"-"</span>);</span><br><span class="line">  <span class="keyword">if</span> (n.right)</span><br><span class="line">    print_bitree(*(n.right));</span><br><span class="line">  <span class="keyword">else</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"-"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>还记得Python类中的那个self吗？我们试着来实现一下！</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">People</span>&#123;</span></span><br><span class="line">  <span class="keyword">char</span> * name;</span><br><span class="line">  <span class="keyword">int</span> age;</span><br><span class="line">&#125;People,*_People;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 模拟main环境</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">object_main</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc set方法</span></span><br><span class="line"><span class="comment"> * - 实现 对 参数self结构体赋值</span></span><br><span class="line"><span class="comment"> * @param (const _People) self _People的地址 不可以在函数内发生改变</span></span><br><span class="line"><span class="comment"> * @param (char*) name 姓名的字符串</span></span><br><span class="line"><span class="comment"> * @return (void) [打印地址，不返回参数]</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setName</span><span class="params">(<span class="keyword">const</span> _People self,<span class="keyword">char</span> * name)</span></span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc set方法</span></span><br><span class="line"><span class="comment"> * - 实现 对 参数self结构体赋值</span></span><br><span class="line"><span class="comment"> * @param (const _People) self _People的地址 不可以在函数内发生改变</span></span><br><span class="line"><span class="comment"> * @param (int) age 年龄</span></span><br><span class="line"><span class="comment"> * @return (void) [打印地址，不返回参数]</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setAge</span><span class="params">(<span class="keyword">const</span> _People self,<span class="keyword">int</span> age)</span></span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc get方法</span></span><br><span class="line"><span class="comment"> * - 实现 对 参数self结构体赋值</span></span><br><span class="line"><span class="comment"> * @param (const _People) self _People的地址 不可以在函数内发生改变</span></span><br><span class="line"><span class="comment"> * @return (char*) name 姓名的字符串</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">char</span> * <span class="title">getName</span><span class="params">(<span class="keyword">const</span> _People self)</span></span>;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @desc set方法</span></span><br><span class="line"><span class="comment"> * - 实现 对 参数self结构体赋值</span></span><br><span class="line"><span class="comment"> * @param (const _People) self _People的地址 不可以在函数内发生改变</span></span><br><span class="line"><span class="comment"> * @return (int) age 年龄</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">getAge</span><span class="params">(<span class="keyword">const</span> _People self)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">object_main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  People son9wx;</span><br><span class="line">  setName(&amp;son9wx,<span class="string">"songwx\0"</span>);</span><br><span class="line">  setAge(&amp;son9wx,<span class="number">18</span>);</span><br><span class="line">  <span class="built_in">printf</span>(<span class="string">"user name is %s\n"</span>,getName(&amp;son9wx));</span><br><span class="line">  <span class="built_in">printf</span>(<span class="string">"user old is %d\n"</span>,getAge(&amp;son9wx));</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setName</span><span class="params">(_People self,<span class="keyword">char</span> * name)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  self-&gt;name = name;</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setAge</span><span class="params">(_People self,<span class="keyword">int</span> age)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  self-&gt;age = age;</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">char</span> * <span class="title">getName</span><span class="params">(_People self)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">return</span> self-&gt;name;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">getAge</span><span class="params">(_People self)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">return</span> self-&gt;age;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h1 id="Chapter-7-name-”后记-0”"><a href="#Chapter-7-name-”后记-0”" class="headerlink" title="Chapter[7].name=”后记\0”"></a>Chapter[7].name=”后记\0”</h1><p>我在上数据结构课程的时候老师经常与我们互动，他对我很是困惑，虽然我可以在课堂上给出正确的答案，但是我的解题过程往往惨不忍睹，当我意识到这一点的时候，我开始改变，看是注重过程，开始注重变化，这让我安静了不少，同时再回头看自己写的程序的时候，确实发现很多不好的习惯，让我无法准确找到自己的错误，经常拆了东墙补西墙。但是改正的过程很痛苦，良好的习惯在一开始就形成的话会让你事半功倍，这篇文章虽然知识不多，但是能带给你很多良好的习惯。在指针中粗心大意往往会带来不可估计的后果，野指针，访问NULL都会让你的程序出现错误，希望你在编写时先想好再去写，你需要一份完整的图示或者说明去实现你的程序，这是一种优质的习惯，也是一个优质程序员</p>
<p><em>代码地址： <a href="https://gitee.com/son9wx/overcome-pointers" target="_blank" rel="noopener">https://gitee.com/son9wx/overcome-pointers</a></em><br><em>阅读版下载：链接：<a href="https://pan.baidu.com/s/1xaqAd-98wegaAYcW8iSQeg" target="_blank" rel="noopener">https://pan.baidu.com/s/1xaqAd-98wegaAYcW8iSQeg</a> 提取码：q6zq</em> </p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/hexo-blog/good-diet/" rel="prev" title="《好好吃饭》读书感悟">
                《好好吃饭》读书感悟 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">son9wx</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/hexo-blog/archives/">
              
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-0-name-”前言-0”"><span class="nav-number">1.</span> <span class="nav-text">Chapter[0].name=”前言\0”</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-gt-node-name-”为什么要写本报告-0”"><span class="nav-number">1.1.</span> <span class="nav-text">Chapter-&gt;*(node).name=”为什么要写本报告\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-gt-node-1-name-”源于对未知事物的恐惧-0”"><span class="nav-number">1.2.</span> <span class="nav-text">Chapter-&gt;*(node+1).name=”源于对未知事物的恐惧\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-gt-node-2-name-”排版说明-0”"><span class="nav-number">1.3.</span> <span class="nav-text">Chapter-&gt;*(node+2).name=”排版说明\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-gt-node-3-name-”致谢-0”"><span class="nav-number">1.4.</span> <span class="nav-text">Chapter-&gt;*(node+3).name=”致谢\0”</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-1-name-”愤怒的送餐员-0”"><span class="nav-number">2.</span> <span class="nav-text">Chapter[1].name=”愤怒的送餐员\0”</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-1-gt-node-name-”李刚刚的故事-0”"><span class="nav-number">2.1.</span> <span class="nav-text">Chapter+1-&gt;*(node).name=”李刚刚的故事\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-1-gt-node-1-name-”送餐员的需要-0”"><span class="nav-number">2.2.</span> <span class="nav-text">Chapter+1-&gt;*(node+1).name=”送餐员的需要\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-1-gt-node-2-name-”确定唯一的信息-0”"><span class="nav-number">2.3.</span> <span class="nav-text">Chapter+1-&gt;*(node+2).name=”确定唯一的信息\0”</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-2-name-”程序中的地址-0”"><span class="nav-number">3.</span> <span class="nav-text">Chapter[2].name=”程序中的地址\0”</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-2-gt-node-name-”取地址-amp-0”"><span class="nav-number">3.1.</span> <span class="nav-text">Chapter+2-&gt;*(node).name=”取地址\&amp;\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-2-gt-node-1-name-”间接访问-0”"><span class="nav-number">3.2.</span> <span class="nav-text">Chapter+2-&gt;(node+1).name=”间接访问\\0”</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-3-name-”指针模型-0”"><span class="nav-number">4.</span> <span class="nav-text">Chapter[3].name=”指针模型\0”</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-3-gt-node-name-”思维转变-0”"><span class="nav-number">4.1.</span> <span class="nav-text">Chapter+3-&gt;*(node).name=”思维转变\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-3-gt-node-1-name-”简单模型-0”"><span class="nav-number">4.2.</span> <span class="nav-text">Chapter+3-&gt;*(node+1).name=”简单模型\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-3-gt-node-2-name-”一级指针模型-0”"><span class="nav-number">4.3.</span> <span class="nav-text">Chapter+3-&gt;*(node+2).name=”一级指针模型\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-3-gt-node-3-name-”二级多级指针模型-0”"><span class="nav-number">4.4.</span> <span class="nav-text">Chapter+3-&gt;*(node+3).name=”二级多级指针模型\0”</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-4-name-”换不过来的交换-0”"><span class="nav-number">5.</span> <span class="nav-text">Chapter[4].name=”换不过来的交换\0”</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-4-gt-node-name-”最简单的交换-0”"><span class="nav-number">5.1.</span> <span class="nav-text">Chapter+4-&gt;*(node).name=”最简单的交换\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-4-gt-node-1-name-”函数的交换-0”"><span class="nav-number">5.2.</span> <span class="nav-text">Chapter+4-&gt;*(node+1).name=”函数的交换\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-4-gt-node-2-name-”地址的交换-0”"><span class="nav-number">5.3.</span> <span class="nav-text">Chapter+4-&gt;*(node+2).name=”地址的交换\0”</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-5-name-”字符指针-0”"><span class="nav-number">6.</span> <span class="nav-text">Chapter[5].name=”字符指针\0”</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-5-gt-node-name-”详解-0”"><span class="nav-number">6.1.</span> <span class="nav-text">Chapter+5&gt;*(node).name=”详解\0”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-5-gt-node-1-name-”寻找大兵雷恩-0”"><span class="nav-number">6.2.</span> <span class="nav-text">Chapter+5-&gt;*(node+1).name=”寻找大兵雷恩\0”</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-6-name-”其他案例-0”"><span class="nav-number">7.</span> <span class="nav-text">Chapter[6].name=”其他案例\0”</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Chapter-7-name-”后记-0”"><span class="nav-number">8.</span> <span class="nav-text">Chapter[7].name=”后记\0”</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">son9wx</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/hexo-blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/hexo-blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/hexo-blog/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/hexo-blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/hexo-blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/hexo-blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
